package com.ms.architecture.status

import android.content.BroadcastReceiver
import android.content.Context
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.ms.architecture.utils.ScanUtil

class ScanStateManager(private val context: Context) : DefaultLifecycleObserver {

    private var mReceiver: BroadcastReceiver? = null

    fun setReceiver(receiver: BroadcastReceiver?) {
        mReceiver = receiver
    }

    override fun onResume(owner: LifecycleOwner) {
        super.onResume(owner)
        mReceiver?.let { ScanUtil.registerScanBroadcastReceiver(context, it) }
    }

    override fun onPause(owner: LifecycleOwner) {
        super.onPause(owner)
        mReceiver?.let { ScanUtil.unRegisterScanBroadcastReceiver(context, it) }
    }
}